import { reactive } from 'vue'


const loginiphon = (rule, value, callback) => {
    let reg = /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/
    if (reg.test(value)) {
        callback()
    } else {
        callback(new Error('未输入正确的手机号码'))
    }
}

const loginvalidateCaptcha2 = (rule, value, callback) => {
    let reg = /^[0-9]{5}$/
    if (reg.test(value)) {
        callback()
    } else {
        callback(new Error('验证码只能是5位的数字'))
    }
}
export const useLoginState =(validateSuccess, validateDefeat)=> (formEl) => {
    if (!formEl) return
    formEl.validate((valid) => {
        if (valid) {
            if (validateSuccess) {
                validateSuccess()
            }
        } else {
            validateDefeat()
            return false
        }
    })
}

export const rules = reactive({
    iphonNum: [{ validator: loginiphon, trigger: 'blur' }],
    validateCaptcha2: [{ validator: loginvalidateCaptcha2, trigger: 'blur' }],
})